/** * 风险金 */
<template>
  <Card style="height:800px">
    <header>
      <span>描述:</span>
      <Input v-model="desc" style="width:200px" placeholder="请输入"></Input>
      <Button type="primary" @click="queryPage" style="margin-left: 10px;">查询</Button>
      <Button type="primary" @click="addItem();" style="margin-left: 10px;">新建</Button>
    </header>
    <Content style="margin-top:20px;">
      <Table border :columns="columns1" :data="data1"></Table>
    </Content>
    <div class="page-box">
      <Page :total="totalNumber" size="small" :current="currentPage" :page-size="pageSize" show-total @on-change="pageIndexChange"></Page>
    </div>
  </Card>
</template>

<script>
export default {
  data () {
    return {
      path: this.$route.path,

      $ajax: null,

      desc: '',

      totalNumber: 0, // 总记录数

      currentPage: 1, // 当前页码

      pageSize: 10, // 页大小

      columns1: [{
        title: 'ID',
        key: 'riskFeeId',
        align: 'center',
        width: 100,
        type: 'index'
        // render: (h, params) => {
        //   var vm = this
        //   return h('div', [
        //     h(
        //       'a', {
        //         style: {
        //           textDecoration: 'underline'
        //         },
        //         on: {
        //           click: function () {
        //             vm.$router.push({
        //               path: vm.path + '/editor',
        //               query: {
        //                 index: params.row.riskFeeId,
        //                 type: 2
        //               }
        //             })
        //           }
        //         }
        //       },
        //       params.row.riskFeeId
        //     )
        //   ])
        // }
      },
      {
        title: '描述',
        align: 'center',
        key: 'description'
      },
      {
        title: '状态',
        key: 'status',
        align: 'center',
        render: function (h, param) {
          const status = param.row.status
          switch (status) {
            case 0:
              return h('div', '使用中')
            case 1:
              return h('div', '拒绝')
            case 9:
              return h('div', '待审核')
            case 10:
              return h('div', '停用')
            default:
              return h('div', '')
          }
        }
      },
      {
        title: '操作',
        align: 'center',
        width: 300,
        render: function (h, param) {
          const vm = this
          return h('div', {}, [
            (param.row.status === 9 || param.row.status === 1) &&
            h(
              'Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '12px',
                  marginLeft: '5px'
                },
                on: {
                  click: () => {
                    this.$Modal.confirm({
                      title: '风险金审核',

                      content: '通过?',

                      okText: '确定',

                      cancelText: '取消',
                      onOk: () => {
                        var datas = {
                          riskFeeId: param.row.riskFeeId,
                          status: 0,
                          checkDesc: true
                        }
                        vm.$ajax
                          .post(
                            vm.$appContext.marvels_core_product +
                            '/product/param/riskfee/service/updateStatus',
                            datas
                          )
                          .then(re => {
                            var data = re.data
                            var code = data.code
                            if (code === 'success') {
                              param.row.status = 0
                            }
                          })
                          .catch(er => { })
                      }
                    })
                  }
                }
              },
              '通过'
            ),
            param.row.status === 9 &&
            h(
              'Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '12px',
                  marginLeft: '5px'
                },
                on: {
                  click: () => {
                    this.$Modal.confirm({
                      title: '风险金审核',

                      content: '拒绝?',

                      okText: '确定',

                      cancelText: '取消',
                      onOk: () => {
                        var datas = {
                          riskFeeId: param.row.riskFeeId,
                          status: 1,
                          checkDesc: true
                        }
                        vm.$ajax
                          .post(
                            vm.$appContext.marvels_core_product +
                            '/product/param/riskfee/service/updateStatus',
                            datas
                          )
                          .then(re => {
                            var data = re.data
                            var code = data.code
                            if (code === 'success') {
                              param.row.status = 1
                            }
                          })
                          .catch(er => { })
                      }
                    })
                  }
                }
              },
              '拒绝'
            ),
            param.row.status === 10 &&
            h(
              'Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '12px',
                  marginLeft: '5px'
                },
                on: {
                  click: () => {
                    this.$Modal.confirm({
                      title: '风险金审核',

                      content: '使用?',

                      okText: '确定',

                      cancelText: '取消',
                      onOk: () => {
                        var datas = {
                          riskFeeId: param.row.riskFeeId,
                          status: 0,
                          checkDesc: true
                        }
                        vm.$ajax
                          .post(
                            vm.$appContext.marvels_core_product +
                            '/product/param/riskfee/service/updateStatus',
                            datas
                          )
                          .then(re => {
                            var data = re.data
                            var code = data.code
                            if (code === 'success') {
                              param.row.status = 0
                            }
                          })
                          .catch(er => { })
                      }
                    })
                  }
                }
              },
              '使用'
            ),
            param.row.status === 0 &&
            h(
              'Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '12px',
                  marginLeft: '5px'
                },
                on: {
                  click: () => {
                    this.$Modal.confirm({
                      title: '风险金审核',

                      content: '停用?',

                      okText: '确定',

                      cancelText: '取消',
                      onOk: () => {
                        var datas = {
                          riskFeeId: param.row.riskFeeId,
                          status: 10,
                          checkDesc: true
                        }

                        vm.$ajax
                          .post(
                            vm.$appContext.marvels_core_product +
                            '/product/param/riskfee/service/updateStatus',
                            datas
                          )
                          .then(re => {
                            var data = re.data
                            var code = data.code
                            if (code === 'success') {
                              param.row.status = 10
                            }
                          })
                          .catch(er => { })
                      }
                    })
                  }
                }
              },
              '停用'
            ),
            // param.row.status === 9 && !vm.$route.meta.isFromCheck &&
            h(
              'Button', {
                props: {
                  type: 'info',
                  size: 'small'
                },
                style: {
                  fontSize: '12px',
                  marginLeft: '5px'
                },
                on: {
                  click () {
                    // vm.$router.push( vm.path + 'editor' );
                    vm.$router.push({
                      path: vm.path + '/editor',
                      query: {
                        index: param.row.riskFeeId,
                        type: 1
                      }
                    })
                  }
                }
              },
              ' 编辑'
            ),
            h(
              'Button',
              {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '12px',
                  marginLeft: '5px'
                },
                on: {
                  click: () => {
                    vm.$router.push({
                      path: vm.path + '/editor',
                      query: {
                        index: param.row.riskFeeId,
                        type: 2
                      }
                    })
                  }
                }
              },
              '查看'
            ),
            h(
              'Button',
              {
                props: {
                  type: 'error',
                  size: 'small'
                },
                style: {
                  fontSize: '12px',
                  marginLeft: '5px'
                },
                on: {
                  click () {
                    vm.$Modal.confirm({
                      title: '风险金',

                      content: '确定删除?',

                      okText: '确定',

                      cancelText: '取消',
                      onOk: () => {
                        var params = {
                          riskFeeId: param.row.riskFeeId
                        }
                        vm.$ajax
                          .post(
                            vm.$appContext.marvels_core_product +
                        '/product/param/riskfee/service/delete',
                            params
                          )
                          .then(re => {
                            var data = re.data
                            var code = data.code
                            var message = data.message
                            if (code === 'success') {
                              vm.$Message.success(message)
                            } else {
                              vm.$Message.warn(data.data)
                            }
                            vm.queryPage()
                          })
                      }
                    })
                  }
                }
              },
              '删除'
            )
          ])
        }.bind(this)
      }
      ],

      data1: []
    }
  },

  methods: {
    pageIndexChange (pageIndex) {
      this.currentPage = pageIndex
      this.queryPage()
    },

    initPage () {
      this.queryPage()
    },

    queryPage () {
      const vm = this
      if (vm.desc.length > 30) {
        this.$Message.warning('查询参数输入过长')
        return
      }
      var params = {
        currentPage: vm.currentPage,
        pageSize: vm.pageSize,
        desc: vm.desc
      }
      vm.$ajax
        .post(
          vm.$appContext.marvels_core_product +
          '/product/param/riskfee/service/list',
          params
        )
        .then(re => {
          var data = re.data
          var code = data.code
          var message = data.message
          if (code !== 'success') {
            this.$Message.warning(message)
            return
          }
          vm.data1 = re.data.data.list
          vm.totalNumber = re.data.data.total
        })
        .catch(er => { })
    },

    addItem () {
      this.$router.push({
        name: 'risk-option-editor',
        query: {
          type: 0
        }
      })
    }
  },

  created () {
    // 初始化当前页面请求对象实例
    this.$ajax = this.$util.ajax()
    this.initPage()
  }
}
</script>

<style lang="less">
@import '../../../styles/common.less';
@import '../../../styles/table.less';
</style>
